<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
class messengers {
    var $id;
var $user_from;
var $user_to;
var $message;
var $chat_date;


    function open(){
        global $db;
        $sql="select * from _messengers where id=$id";
        $row=$db->fetch_row($sql);
        if (!empty($row)){
            extract($row);
            $this->user_from=$user_from;
$this->user_to=$user_to;
$this->message=$message;
$this->chat_date=$chat_date;

        }
    }

    function openAll(){
        $sql="select * from _messengers order by id asc";
        $result=$db->query($sql);
        return $db->fetch_array($result);
        
    }

    function insert(){
    global $db;
    $sql="insert into _messengers values (null,'{$this->user_from}',
'{$this->user_to}','{$this->message}',sysdate())";
    $db->query($sql);
    return mysql_insert_id();
    }

    function update(){
        global $db;
        $sql="update _messengers set user_from='{$this->user_from}',
user_to='{$this->user_to}',
message='{$this->message}',
chat_date='{$this->chat_date}' where id={$this->id}";
        $db->query($sql);
    }

    function delete(){
        global $db;
        $sql="delete from _messengers where id=".$this->id;
        $db->query($sql);
    }

}
?>
